#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_key.h"
#include "bsp_usart.h"
#include "bsp_can.h"

uint32_t TxID = 0x1314;
uint8_t TxLength = 8;
uint8_t TxData[8] = {0, 1, 2, 3, 4, 5, 6, 7};

uint32_t RxID;
uint8_t RxLength;
uint8_t RxData[8];

int main(void)
{	
  LED_GPIO_Config();	
  Key_GPIO_Config();
  USART_Config();
  CAN_Config();

	printf("This is CAN Loop Experiment!\r\n");
  
  while(1)
	{	
    if (Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN) == KEY_ON  )
		{
      LED_BLUE;
      for (uint8_t i = 0; i < TxLength; i++)
      {
        TxData[i] ++;
      }
      CAN_Transmit_Config(TxID, TxLength, TxData);
    }
    if (CAN_ReceiverFlag_Config())
		{
			CAN_Receive_Config(&RxID, &RxLength, RxData);
      printf("\r\n < -- RxID: 0x%x \t RxLength: %d -- >\r\n", RxID, RxLength);
      for (uint8_t i = 0; i < RxLength; i ++)
      {
        printf("RxData[%d]: %d\t", i, RxData[i]);
      }
      printf("\r\n");
		}
	}	
}
/*********************************************END OF FILE**********************/
